<template>
  <div>
    <el-button-group>
      <el-button type="success" @click="add">新增</el-button>
      <el-button type="warning">修改</el-button>
      <el-button type="danger">删除</el-button>
    </el-button-group>

    <el-table
      ref="multipleTable"
      :data="tableData"
      tooltip-effect="dark"
      style="width: 100%;margin:20px 0;"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55"></el-table-column>
      <el-table-column type="index" width="55"></el-table-column>
      <el-table-column prop="title" label="标题"></el-table-column>
      <el-table-column prop="price" label="价格"></el-table-column>
      <el-table-column prop="zhekou" label="折扣"></el-table-column>
      <el-table-column prop="tuangou" label="团购"></el-table-column>
      <el-table-column prop="djs" label="倒计时"></el-table-column>
      <el-table-column prop="img" label="图片" show-overflow-tooltip></el-table-column>
      <el-table-column prop="content" label="内容"></el-table-column>
    </el-table>

    <div class="block">
      <el-pagination
        layout="prev, pager, next"
        :total="total"
        :page-size="pageSize"
        :currentPage="currentPage"
        @current-change="getPage"
      ></el-pagination>
    </div>
  </div>
</template>

<script>
import axios from "axios";
import ClassifyForm from "./ClassifyForm";
export default {
  components: {
    ClassifyForm
  },
  mounted() {
    this.getList();
  },
  data() {
    return {
      tableData: [],
      checkAll: [],
      total: 0,
      pageSize: 5,
      currentPage: 1
    };
  },
  methods: {
    getList() {
      axios({
        method: "get",
        url: "http://localhost/yssc/api.php/pjzq",
        params: {
          transform: 1,
          order: "id,desc",
          page: `${this.currentPage},${this.pageSize}`
        }
      }).then(res => {
        this.tableData = res.data.pjzq;
        this.total = res.data._results;
      });
    },
    handleSelectionChange(val) {
      this.checkAll = val;
      console.log(val);
    },
    getPage(page) {
      this.currentPage = page;
      this.getList();
      console.log(page);
    },
    add() {
      this.$router.push({ name: "cyf", params: { name: "pjzq" } });
    }
  }
};
</script>

<style>
</style>
